package zt.ser;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;

public class DemoService extends Service implements Runnable {

	
	private boolean isRun = false;
	private LocalBinder binder = new LocalBinder();
	private long rundate;
	
	
	
	public long getRundate() {
		return rundate;
	}


	class LocalBinder extends Binder{
	  
		public DemoService getService(){
			return DemoService.this;
		}
	}
	
	public IBinder onBind(Intent intent) {
		Log.e("-----------onbind method ", "onbind invoked");
		isRun = true;
		new Thread(this).start();
		return binder;
	}

	public void onCreate() {
		// TODO Auto-generated method stub
		Log.e("-----------onCreate method ", "onCreate invoked");
		super.onCreate();
	}

	public void onDestroy() {
		super.onDestroy();
		Log.e("-----------onDestroy method ", "onDestory invoked");
		isRun = false;
		
	}
	
	

	public void onRebind(Intent intent) {
		Log.e("-----------onReBind method ", "onRebind invoked");
		super.onRebind(intent);
	}


	public void onStart(Intent intent, int startId) {
		super.onStart(intent, startId);
		Bundle bundle = intent.getExtras();		
		Log.e("-----------onStart method ", "onStart invoked:"+bundle.getString("name")+":"+startId);
		isRun = true;
		new Thread(this).start();
	}

	@Override
	public boolean onUnbind(Intent intent) {
		Log.e("-----------onUnbind method ", "onUnbind invoked");
		super.onUnbind(intent);
		return true;
	}


	public void run() {
		while(isRun) {
			try {
				Thread.sleep(4000);
				rundate = System.currentTimeMillis();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
	       Log.e("-----------DemoService ", "time:"+System.currentTimeMillis());	
		}		
		Log.e("===================", "thread");
	}

}
